/*
 * YIQDialog.java
 *
 * Created on Sep 19, 2011, 8:00:06 PM
 */
package com.photoexpert;

/**
 *
 * @author PANYIXIN
 */
class YIQDialog extends javax.swing.JDialog {

    YIQDialog() {
        super(App.Instance(), true);
        initComponents();
        setLocation(200, 200);
        ((PreviewPane)_previewPane).setOp(null);
        setVisible(true);
    }

    private void preview() {
        int yValue = _ySlider.getValue();
        int iValue = _iSlider.getValue();
        int qValue = _qSlider.getValue();
        if(yValue == 0 && iValue == 0 && qValue == 0)
            _op = null;
        else
            _op = new YIQOp(1f, yValue, 1f, iValue, 1f, qValue, null);
        ((PreviewPane)_previewPane).setOp(_op);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _ySlider = new javax.swing.JSlider();
        _previewLabel = new javax.swing.JLabel();
        _previewPane = PreviewPane.CreateInstance();
        _cancel = new javax.swing.JButton();
        _ok = new javax.swing.JButton();
        _yLabel = new javax.swing.JLabel();
        _iLabel = new javax.swing.JLabel();
        _qSlider = new javax.swing.JSlider();
        _qLabel = new javax.swing.JLabel();
        _iSlider = new javax.swing.JSlider();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("YIQ Adjustor");
        setModal(true);
        setResizable(false);

        _ySlider.setMajorTickSpacing(20);
        _ySlider.setMinimum(-100);
        _ySlider.setMinorTickSpacing(10);
        _ySlider.setPaintLabels(true);
        _ySlider.setPaintTicks(true);
        _ySlider.setValue(0);
        _ySlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                _ySliderStateChanged(evt);
            }
        });

        _previewLabel.setText("Preview:");

        _previewPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        _previewPane.setPreferredSize(new java.awt.Dimension(252, 192));

        javax.swing.GroupLayout _previewPaneLayout = new javax.swing.GroupLayout(_previewPane);
        _previewPane.setLayout(_previewPaneLayout);
        _previewPaneLayout.setHorizontalGroup(
            _previewPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 250, Short.MAX_VALUE)
        );
        _previewPaneLayout.setVerticalGroup(
            _previewPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 190, Short.MAX_VALUE)
        );

        _cancel.setText("Cancel");
        _cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _cancelActionPerformed(evt);
            }
        });

        _ok.setText("OK");
        _ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _okActionPerformed(evt);
            }
        });

        _yLabel.setText("Y:");

        _iLabel.setText("I:");

        _qSlider.setMajorTickSpacing(20);
        _qSlider.setMinimum(-100);
        _qSlider.setMinorTickSpacing(10);
        _qSlider.setPaintLabels(true);
        _qSlider.setPaintTicks(true);
        _qSlider.setValue(0);
        _qSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                _qSliderStateChanged(evt);
            }
        });

        _qLabel.setText("Q:");

        _iSlider.setMajorTickSpacing(20);
        _iSlider.setMinimum(-100);
        _iSlider.setMinorTickSpacing(10);
        _iSlider.setPaintLabels(true);
        _iSlider.setPaintTicks(true);
        _iSlider.setValue(0);
        _iSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                _iSliderStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_yLabel)
                            .addComponent(_iLabel)
                            .addComponent(_qLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_qSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
                            .addComponent(_iSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
                            .addComponent(_ySlider, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(_previewPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_cancel, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                            .addComponent(_ok, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(_previewLabel)
                        .addContainerGap(296, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(_yLabel)
                    .addComponent(_ySlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(_iLabel)
                    .addComponent(_iSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(_qLabel)
                    .addComponent(_qSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(_previewLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(_ok)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(_cancel))
                    .addComponent(_previewPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void _ySliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event__ySliderStateChanged
        preview();
    }//GEN-LAST:event__ySliderStateChanged

    private void _okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__okActionPerformed
        if(_op != null)
            Implementor.Instance().adjust(_op);
        setVisible(false);
        dispose();
    }//GEN-LAST:event__okActionPerformed

    private void _cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__cancelActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event__cancelActionPerformed

    private void _qSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event__qSliderStateChanged
        preview();
    }//GEN-LAST:event__qSliderStateChanged

    private void _iSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event__iSliderStateChanged
        preview();
    }//GEN-LAST:event__iSliderStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _cancel;
    private javax.swing.JLabel _iLabel;
    private javax.swing.JSlider _iSlider;
    private javax.swing.JButton _ok;
    private javax.swing.JLabel _previewLabel;
    private javax.swing.JPanel _previewPane;
    private javax.swing.JLabel _qLabel;
    private javax.swing.JSlider _qSlider;
    private javax.swing.JLabel _yLabel;
    private javax.swing.JSlider _ySlider;
    // End of variables declaration//GEN-END:variables
    private YIQOp   _op;
}
